/*
@Author: bevin

@Created on: 2016-12-09 10:36:59
*/
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	numbers := readfile("e13_data.txt")
	result := make([]int, 0, 55)
	step := 0
	for i := len(numbers[0]) - 1; i >= 0; i-- {
		cur := 0
		for j := 0; j < len(numbers); j++ {
			cur += numbers[j][i]
		}
		cur += step
		result = append(result, cur%10)
		step = cur / 10
	}

	for step != 0 {
		result = append(result, step%10)
		step /= 10
	}

	for i := len(result) - 1; i >= len(result)-10; i-- {
		fmt.Print(result[i])
	}
	fmt.Println()
}

func readfile(filename string) (numbers [100][50]int) {
	f, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	bfRd := bufio.NewReader(f)
	count := 0
	for {
		line, err := bfRd.ReadBytes('\n')
		for i, ch := range strings.Replace(string(line), "\r\n", "", -1) {
			numbers[count][i] = int(ch) - 48
		}
		if err != nil {
			break
		}
		count++
	}
	return
}
